/**
 * 
 * 
 * Defender
 * 2013-3-14
 */
package com.ls.fw.web.core.servlet.listener;

import java.util.Enumeration;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.ls.fw.web.core.support.WebContext;


/**
 * 检测用户是否离线
 * @author Defender
 * 2013-3-14
 */
public class ServerInitListener implements ServletContextListener {

	protected final Logger logger = LoggerFactory.getLogger(this.getClass());
	 
	/* (non-Javadoc)
	 * @see javax.servlet.ServletContextListener#contextDestroyed(javax.servlet.ServletContextEvent)
	 */
	@Override
	public void contextDestroyed(ServletContextEvent arg0) {
		// TODO Auto-generated method stub
		System.out.println("contextDestroyed");
	}

	/* (non-Javadoc)
	 * @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent)
	 */
	@Override
	public void contextInitialized(final ServletContextEvent arg0) {
		 System.out.println("contextInitialized");
		 System.out.println("正在获取初始化参数。。。");
		 ServletContext application = arg0.getServletContext();
		 Enumeration<String> set = application.getInitParameterNames();
		 if(set!=null){
			while(set.hasMoreElements()){ 
				String key = set.nextElement();
				String v = application.getInitParameter(key);
				WebContext.map.put(key, v);
				System.out.println(key+"="+v);
			}
		 }
		 WebContext.setServletContext(application);
		 WebContext.map.put("realPath", application.getRealPath("/").replaceFirst("/", ""));
		 WebContext.map.put("contextPath", application.getContextPath());
		 WebContext.map.put(WebContext.SYS_REALPATH, application.getRealPath("/"));
		 System.out.println("获取初始化参数完毕！");
	}

}
